#include "precompile.h"

#include "MenuBar.h"
#include "form/IMenu.h"

MenuBar::MenuBar()
{
}

MenuBar::~MenuBar()
{
}

IMenu* MenuBar::Add(const String& insertpath)
{
	IObject* control = AddControl(CLSID_Menu);
	if (control)
	{
		sys::InterfacePtr<IMenu> pIFMenu(control);
		pIFMenu->SetPath(insertpath);
		return pIFMenu;
	}
	return NULL;
}

IMenu* MenuBar::AddPopup(const String& insertpath)
{
	IMenu* menu = Add(insertpath);
	if(menu)
		menu->SetCommandID(0U);

	return menu;
}

uint32 MenuBar::SelectMenus(kTargetFrame frame,ControlList& controls) const
{
	GetControls(controls);
	ControlList::iterator iter = controls.begin();
	while (!controls.empty() && iter != controls.end())
	{
		sys::InterfacePtr<IMenu> pIFMenu(*iter);
		if (pIFMenu->GetTargetFrame() != frame)
			iter = controls.erase(iter);
		else
			iter++;
	}
	return controls.size();
}